package com.atao.baokede.AiTools;

import com.alibaba.fastjson.JSON;
import com.atao.baokede.pojo.Item;
import com.atao.baokede.service.ItemService;
import org.springframework.ai.tool.annotation.Tool;

import java.io.IOException;
import java.util.List;

/**
 * 数据库商品信息
 */
public class MysqlItemsTool {

    private final ItemService itemService;

    // 添加构造函数用于手动注入
    public MysqlItemsTool(ItemService itemService) {
        this.itemService = itemService;
    }

    @Tool(description = """
            Retrieves the list of the top 20 best-selling products from the '宝可得' e-commerce platform. 
            This tool is useful for generating product recommendations, analyzing popular items, or providing data for marketing strategies. 
            The result is returned as a JSON string containing details of the products (e.g., name, price, sales volume). 
            Invoke this tool when the user asks questions like: 
            'What are the most popular products in 宝可得?', 
            'Can you recommend some best-selling items?', 
            'What products are currently trending?', 
            or any similar queries related to top-selling items.""")
    public String getBestSellingItems() throws IOException {
        List<Item> list = itemService.getBestSellingItems();
        return JSON.toJSONString(list);
    }
}
